//
//  UXLog.h
//  ubixar-framework
//
//  Created by Demis Bellot on 18/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

enum {
	UXLogLevelNone		= 0,
	UXLogLevelAll		= 0xFFFFFFFF,

	UXLogLevelDebug		= 1 << 0, //1
	UXLogLevelInfo		= 1 << 1, //2
	UXLogLevelWarn		= 1 << 2, //4
	UXLogLevelError		= 1 << 3, //8
	UXLogLevelFatal		= 1 << 4  //16
};
typedef NSUInteger UXLogLevel;

enum {
	UXLoggerNone					= 0,
	UXLoggerAll						= 0xFFFFFFFFFFFFFFFF,
	
	UXLoggerSystem					= 1 << 1,
	UXLoggerUI						= 1 << 2,

	UXLoggerSystemReserved			= 0x000000000000FFFF,	//range reserved for internal framework use
	UXLoggerApplicationReserved		= 0xFFFFFFFFFFFF0000,	//range available for application use	
	UXLoggerApplicationDefault      = 1 << 17
};
typedef UInt64 UXLogger;

extern NSUInteger UX_LOG_LEVELS;
extern UInt64 UX_LOG_LOGGERS;

extern void UXLog(UXLogLevel logLevel, UXLogger logger, NSString* format, ...);


/*
	Detailed log, which respects log filters.
	Best to be used with a macro as defined below.
 */
extern void UXDetailLog(UXLogLevel logLevel, 
						UXLogger logger, 
						const char* magicFileName,
						const char* magicFuncName,
						int magicLineNumber,
						NSString* format, 
						...);

extern void UXDetailLogMessage(UXLogLevel logLevel, 
						UXLogger logger, 
					    const char* magicFileName,
					    const char* magicFuncName,
						int magicLineNumber,
						NSString* message);

extern NSString* UXGetApplicationLoggerName(UXLogger logger);

//these can be overridden to use your own custom loggers instead
#ifndef UX_LOGGERS

#ifndef GetApplicationLoggerName
#define GetApplicationLoggerName UXGetApplicationLoggerName
#endif

//aliases for Detailed or Short loggers, drop in replacement for NSLog
#define DLog(format, ...) UXDetailLog(UXLogLevelDebug, UXLoggerApplicationDefault, __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define SLog(format, ...) UXLog(UXLogLevelDebug, UXLoggerApplicationDefault, (format), ##__VA_ARGS__)

//short aliases for different log levels
#define DDLog(logger, format, ...) UXDetailLog(UXLogLevelDebug, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define DILog(logger, format, ...) UXDetailLog(UXLogLevelInfo, (logger), __FILE__, _	_PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define DWLog(logger, format, ...) UXDetailLog(UXLogLevelWarn, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define DELog(logger, format, ...) UXDetailLog(UXLogLevelError, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define DFLog(logger, format, ...) UXDetailLog(UXLogLevelFatal, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)

#define SDLog(logger, format, ...) UXLog(UXLogLevelDebug, (logger), (format), ##__VA_ARGS__)
#define SILog(logger, format, ...) UXLog(UXLogLevelInfo, (logger), (format), ##__VA_ARGS__)
#define SWLog(logger, format, ...) UXLog(UXLogLevelWarn, (logger), (format), ##__VA_ARGS__)
#define SELog(logger, format, ...) UXLog(UXLogLevelError, (logger), (format), ##__VA_ARGS__)
#define SFLog(logger, format, ...) UXLog(UXLogLevelFatal, (logger), (format), ##__VA_ARGS__)

//longer more readable aliases
#define Log(format, ...) UXDetailLog(UXLogLevelDebug, UXLoggerApplicationDefault, __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define LogDebug(logger, format, ...) UXDetailLog(UXLogLevelDebug, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define LogInfo(logger, format, ...) UXDetailLog(UXLogLevelInfo, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define LogWarn(logger, format, ...) UXDetailLog(UXLogLevelWarn, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define LogError(logger, format, ...) UXDetailLog(UXLogLevelError, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)
#define LogFatal(logger, format, ...) UXDetailLog(UXLogLevelFatal, (logger), __FILE__, __PRETTY_FUNCTION__, __LINE__, (format), ##__VA_ARGS__)

#endif

